<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <?php include 'inc/head.php'; ?>
</head>

<body>
  <?php include 'inc/header.php'; ?>

  <div class="container">

    <form method="get" class="form">
      <?php echo M_input(); ?>
      <div class="row">
        <div class="col-sm-2 mb-3">
          <select
            onchange="location.href='?<?php echo M_string(array('cid', 'keyword')); ?>&cid='+this.options[this.selectedIndex].value;"
            class="form-select">
            <option value="0">全部</option>
            <?php
            echo channel_select_list($this->priv, $this->cid);
            if (!empty($this->keyword)) {
              echo '<option selected="selected" >搜索结果</option>';
            }
            ?>
          </select>
        </div>
        <div class="col-sm-2 mb-3">
          <select
            onchange="location.href='<?php echo M('admin', 'detail', 'index') ?>&cid=<?php echo $this->cid; ?>&type='+this.options[this.selectedIndex].value;"
            class="form-select">
            <option value="all" <?php echo $this->type == 'all' ? 'selected="selected"' : ''; ?>>全部</option>
            <option value="rec" <?php echo $this->type == 'rec' ? 'selected="selected"' : ''; ?>>推荐</option>
            <option value="hot" <?php echo $this->type == 'hot' ? 'selected="selected"' : ''; ?>>热门</option>
            <option value="enable" <?php echo $this->type == 'enable' ? 'selected="selected"' : ''; ?>>生效</option>
            <option value="disable" <?php echo $this->type == 'disable' ? 'selected="selected"' : ''; ?>>失效</option>
          </select>
        </div>
        <div class="col-sm-8">
          <div class="input-group">
            <input id="keyword" class="form-control" type="text" name="keyword" placeholder="名称查找" />
            <button type="submit" id="search" class="btn btn-light btn-outline-secondary">检索</button>
          </div>
        </div>
      </div>
    </form>

    <div class="table-responsive">
      <table class="table table-sm table-bordered table-hover">
        <form
          action="<?php echo M('admin', 'detail', 'batch') . '&cid=' . $this->cid . '&keyword=' . $this->keyword; ?>"
          method="post">
          <thead class='bg-light'>
            <tr>
              <th>ID</th>
              <th>排序</th>
              <th>名称</th>
              <th>频道</th>
              <th>属性</th>
              <th>日期</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            <?php
            foreach ($list as $row) {
            ?>
            <tr>
              <td><label for="<?php echo $row['id']; ?>" style="display:block"><input type="checkbox" name="id[]"
                    id="<?php echo $row['id']; ?>" value="<?php echo $row['id']; ?>" /></label>
              </td>
              <td><?php echo $row['d_order']; ?></td>
              <td align="left">
                <?php echo '<a href="/' . d_url($row['id']) . '" target="_blank">' . $row['d_name'] . '</a>'; ?></td>
              <td><?php echo get_channel($row['d_parent'], 'c_name'); ?></td>
              <td>
                <?php
                  echo $row['d_rec'] == 1 ? '<span class="badge bg-success">荐</span> ' : '';
                  echo $row['d_hot'] == 1 ? '<span class="badge bg-danger">热</span> ' : '';
                  echo $row['d_ifslideshow'] == 1 ? '<span class="badge bg-secondary">图</span> ' : '';
                  ?>
              </td>
              <td><?php echo local_date('y-m-d', $row['d_date']); ?></td>
              <td><a
                  href="<?php echo M('admin', 'detail', 'edit', $row['id']); ?>&page=<?php echo $this->page; ?>">编辑</a>
              </td>
            </tr>
            <?php
            }
            ?>
          </tbody>
          <tfoot>
            <tr>
              <th>ID</th>
              <th>排序</th>
              <th>名称</th>
              <th>频道</th>
              <th>属性</th>
              <th>日期</th>
              <th>操作</th>
            </tr>
            <tr>
              <td colspan="7">
                <div class="row">
                  <div class="col-sm-3">
                    <div class="btn-group btn-group-sm">
                      <button type="button" class="btn btn-light btn-outline-secondary" id="check_all">全选</button>
                      <button type="button" class="btn btn-light btn-outline-secondary" id="check_none">不选</button>
                      <button type="button" class="btn btn-light btn-outline-secondary" id="check_invert">反选</button>
                    </div>
                  </div>
                  <div class="col-sm-5">
                    <div class="input-group input-group-sm mb-0">
                      <select id="execute_method" name="execute_method" class="form-select">
                        <option value="">请选择操作</option>
                        <option value="srec">设为推荐</option>
                        <option value="crec">取消推荐</option>
                        <option value="shot">设为热门</option>
                        <option value="chot">取消热门</option>
                        <option value="enable">设为生效</option>
                        <option value="disable">设为失效</option>
                        <option value="delete">删除选中</option>
                      </select>
                      <input type="submit" id="execute" name="execute" class="btn btn-light btn-outline-secondary"
                        onclick="return confirm('确定要执行吗')" value="执行" />
                    </div>
                  </div>
                  <div class="col-sm-4">
                    <div class="input-group input-group-sm mb-0">
                      <select id="shift_target" name="shift_target" class="form-select">
                        <option value="">请选择目标频道</option>
                        <?php echo channel_select_list(0, 0); ?>
                      </select>
                      <input type="submit" id="shift" class="btn btn-light btn-outline-secondary" name="shift"
                        onclick="return confirm('确定要转移吗');" value="转移" />
                    </div>
                  </div>
                </div>
              </td>
            </tr>
          </tfoot>
        </form>
      </table>
    </div>
    <div class="row block-page my-3">
      <div class="col-sm-6">
        <p><?php echo $pager->desc(); ?></p>
      </div>
      <div class="col-sm-6">
        <nav>
          <ul class="pagination pagination-sm justify-content-end"><?php echo $pager->show(); ?></ul>
        </nav>
      </div>
    </div>

  </div>

  <?php include 'inc/footer.php'; ?>

  <!-- js -->
  <script type="text/javascript">
  $(function() {
    $('#check_all').click(function() {
      $('.table td:first-of-type>input').prop('checked', true);
    });
    $('#check_none').click(function() {
      $('.table td:first-of-type>input').prop('checked', false);
    });
    $('#check_invert').click(function() {
      $('.table td:first-of-type>input').each(function() {
        this.checked = !this.checked;
      });
    });
    //操作执行验证
    $('#execute').click(function() {
      if ($('#execute_method').val() == '') {
        alert('请选择一项要执行的操作！');
        return false;
      };
      if ($('.table td:first-of-type>input').val() = '') {
        alert('请至少选择一项！');
        return false;
      };
    });
    //频道转移验证
    $('#shift').click(function() {
      if ($('#shift_target').val() == '') {
        alert('请选择要转移到的频道！');
        return false;
      };
      if ($('.table td:first-of-type>input').val() = '') {
        alert('请至少选择一项！');
        return false;
      };
    });
    //搜索验证
    $('#search').click(function() {
      if ($('#keyword').val() == '') {
        alert('请输入要查找的关键字');
        $('#keyword').focus();
        return false;
      };
    });
  });
  </script>
</body>

</html>